package com.qfjy.config;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;

/**
 * @ClassName JedisConfig
 * @Description TODO   Spring整合jedis客户端
 * @Author guoweixin
 * @Date 2022/3/22
 * @Version 1.0
 */
@Configuration
public class JedisConfig {
    @Value("${spring.redis.database}")
    private int database;
    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private int port;
    @Value("${spring.redis.timeout}")
    private int timeout;
    @Value("${spring.redis.password}")
    private String password;
    @Value("${spring.redis.jedis.pool.min-idle}")
    private int minIdle;
    @Value("${spring.redis.jedis.pool.max-idle}")
    private int maxIdle;
    /**
       JDBC
     1、JDBC连接池  (url/user/password)
     2、连接池获得JDBC 连接：connection
     */
    /**
     * JedisPool  jedis连接池配置
     * @return
     */
    @Bean
    public JedisPool jedisPool(){
        //JedisPool(GenericObjectPoolConfig<Jedis> poolConfig, String host, int port, int timeout, String password)
        /**
         * GenericObjectPoolConfig  连接池基本参数配置
         */
        GenericObjectPoolConfig poolConfig=new GenericObjectPoolConfig();
        //最小空闲连接
        poolConfig.setMinIdle(3);
        //最大连接数
        poolConfig.setMaxIdle(10);
        // this(poolConfig, host, port, timeout, password, 0);
        JedisPool jedisPool=new JedisPool(poolConfig,host,port,timeout,password,database);

        return  jedisPool;
    }

}
